<template>
	<jk-dialog
		v-model="showDialog"
		title="详情-产线"
		width="900px"
		:show-content-loading="showLoading"
		append-to-body
		:show-confirm-btn="false"
		:show-cancel-btn="false"
		@on-close="onVisibleChange(false)"
		@on-visible-change="onVisibleChange"
	>
		<el-form ref="ruleForm" :model="ruleForm" label-width="110px" :show-message="false">
			<div ref="box1" class="margin-bottom-10">
				<el-tag type="primary" effect="plain" class="margin-bottom-4">
					<span class="el-icon-tickets item-gap"></span>
					<span>基本信息</span>
				</el-tag>
				<jk-card>
					<el-row>
						<el-col :span="8">
							<el-form-item class="margin-bottom-10" label="产线编号">
								<span class="read-only-2">{{ ruleForm.code }}</span>
							</el-form-item>
						</el-col>
						<el-col :span="8">
							<el-form-item class="margin-bottom-10" label="产线名称">
								<span class="read-only-2">{{ ruleForm.name }}</span>
							</el-form-item>
						</el-col>
						<el-col :span="8">
							<el-form-item class="margin-bottom-10" label="清花机编号">
								<span class="read-only-2">{{ ruleForm.qhCode }}</span>
							</el-form-item>
						</el-col>
						<el-col :span="8">
							<el-form-item class="margin-bottom-10" label="清花机名称">
								<span class="read-only-2">{{ ruleForm.qhName }}</span>
							</el-form-item>
						</el-col>
						<el-col :span="8">
							<el-form-item class="margin-bottom-10" label="区域">
								<span class="read-only-2">{{ ruleForm.workshopName }}</span>
							</el-form-item>
						</el-col>
						<el-col :span="8">
							<el-form-item class="margin-bottom-10" label="排序">
								<span class="read-only-2">{{ ruleForm.sortNum }}</span>
							</el-form-item>
						</el-col>
						<el-col :span="24">
							<el-form-item class="margin-bottom-0" label="备注">
								<el-input v-model="ruleForm.remark" disabled type="textarea" :rows="1" placeholder="" />
							</el-form-item>
						</el-col>
					</el-row>

				</jk-card>
			</div>
			<div ref="box2" class="margin-bottom-4">
				<el-tag type="primary" effect="plain">
					<span class="el-icon-tickets item-gap"></span>
					<span>关联工序</span>
				</el-tag>
			</div>
			<jk-table border :data="ruleForm.processList || []" :max-height="dialogTableHeight - 20">
				<vxe-column title="工序" align="center" field="processName" :width="110"></vxe-column>
				<vxe-column title="机台" align="left" field="machineList" :min-width="110">
					<template slot-scope="scope">
						<div class="flex-start-center-wrap">
							<div
								v-for="(item, index) in scope.row.machineList"
								:key="index"
								style="padding: 2px;width: calc(100% / 6);flex-shrink: 0;"
							>
								<el-tag
									class="width-100-percent flex-between-center"
									type="info"
								>{{ item.machineName }}</el-tag>
							</div>
						</div>
					</template>
				</vxe-column>
			</jk-table>
		</el-form>
	</jk-dialog>
</template>

<script>
    import calHeight from '/src/mixins/cal-dialog-height';
    import {
        ppfProductionLineGet
    } from '../../../api/production/produtionLine';
    export default {
        props: {
            // 页面权限的前缀
            permissionPrefix: {
                type: String,
                default: ''
            },
            dialogState: {
                type: Boolean,
                default: false
            },
            dataId: {
                type: [String, Number],
                default: ''
            }
        },
        mixins: [calHeight],
        data() {
            return {
                showDialog: false,
                showLoading: true,
                ruleForm: {
                    captureTypeName: ''
                }
            };
        },
        methods: {
            onVisibleChange(e) {
                this.$emit('on-visible-change', e);
                if (!e) {
                    Object.assign(this.$data, this.$options.data());
                }
            },
            getDetailRequest() {
                return ppfProductionLineGet({ id: this.dataId }).then(res => {
                    if (res.data.status === 200) {
                        const resData = res.data.res ? JSON.parse(JSON.stringify(res.data.res)) : {};
                        resData.processList = resData.processList ? resData.processList : [];
                        this.ruleForm = resData;
                    }
                });
            },
            async getDependentData() {
                this.showLoading = true;
                if (this.dataId) await this.getDetailRequest();
                this.showLoading = false;
            }
        },
        watch: {
            dialogState(newVal) {
                this.showDialog = newVal;
                if (newVal) {
                    this.getDependentData();
                }
            }
        }
    };
</script>
